/**
 * 详情对话框
 */
var CategoryInfoDlg = {
    data: {
        categoryName: "",
        icon: "",
        weights: "",
        level: "",
        parentId: "",
        revision: "",
        isImportant: "",
        createTime: "",
        updateTime: "",
        recordStatus: ""
    },
    prev: {
        pName: "",
        parentId: ""
    }
};

layui.use(['form', 'admin', 'ax',"simTool"], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var simTool = layui.simTool;

    //让当前iframe弹层高度适应
    admin.iframeAuto();

    //图标上传
    var sim=new simTool("/upload","#iconPicBox")
    sim.uploadImg()

    //获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/category/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    form.val('categoryForm', result.data);
    $("#iconPicBox").find("img").attr("src",Feng.ctxPath+result.data.icon);
    Feng.buttonInit("isImportant",result.data.isImportant);
    if(result.data.level==1){
        $("#homeCategory").css("display","block");
    }else{
        $("#homeCategory").css("display","none");
    }
    // 点击父级菜单
    $('#pName').click(function () {
        var formName = encodeURIComponent("parent.CategoryInfoDlg.prev.pName");
        var formId = encodeURIComponent("parent.CategoryInfoDlg.prev.parentId");
        var treeUrl = encodeURIComponent("/category/selectCategoryTreeList");
        layer.open({
            type: 2,
            title: '父级菜单',
            area: ['300px', '400px'],
            content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
            end: function () {
                $("#parentId").val(CategoryInfoDlg.prev.parentId);
                $("#pName").val(CategoryInfoDlg.prev.pName);
                var parentId = CategoryInfoDlg.prev.parentId;
                if(parentId =="" || parseInt(parentId)<=0){
                    //改为父类
                    $("#homeCategory").css("display","block");
                    $("#level").val(1)
                }else{
                    //改为子类
                    $("#homeCategory").css("display","none");
                    $("#isImportant").removeAttr("checked");
                    $("#level").val(2)

                }
            }
        });
    });


    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/category/editItem", function (data) {
            Feng.success("更新成功！");

            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("更新失败！" + data.responseJSON.message)
        });
        ajax.set("isImportant",$("#isImportant").attr("checked")=="checked"?1:0);
        $("#iconPicBox").find("img").attr("src");
        ajax.set(data.field);
        ajax.start();
    });
    /**
     * 开关的逻辑处理
     */



});